﻿#ifndef MESTRUTIL_H
#define MESTRUTIL_H

#include <QString>
#include <Eigen/Core>
//----opencv---
#ifndef ME_NO_CV
#include <opencv2/core.hpp>
#endif
#include <memath/MePoint.h>
#include <memath/MePose.h>


/// 字符串相关的工具封装
class MeStrUtil
{
public:
    /// 任意的double数组转成字符串，中间用，隔开
    static QString doublesToQStr(double values[], int size);
    static void doublesFromQStr(QString &str, std::vector<double> &values);
    /// 将MePose.v 转成字符串
    static QString poseToQStr(double values[6]);
    /// 生成 MePose.v
    static void poseFromQStr(QString &str, double v[6]);
    static void poseFromStr(std::string &str, double v[6]);
    static void poseFromStr(std::string &str, MePose &pose);
    static void jointsFromStr(std::string &str, double jv[]);
    static void jointsFromStr(std::string &str, MeJoints &joints);
    /// 将 MePoint3D.v 转成字符串
    static QString point3dToQStr(double values[3]);
    static QString point3dToQStr(const double values[3]);
    static QString point3dToQStr3Prec(double values[3]);
    static QString point3dToQStr3Prec(const double values[3]);

    /// 生成 MePoint3D.v
    static void point3dFromQStr(QString &str, double values[3]);
    static void point3dFromStr(std::string &str, double values[3]);

    // --- vector ---
    /// 字符串中解析数组点
    static void pointsFromQString(QString &strPts, std::vector<MePoint3D> &pts);
    static void pointsFromQString(QString &strPts, std::vector<Eigen::Vector3d> &pts);
    /// 点集转成字符串
    static QString pointsToQString(const std::vector<MePoint3D> &pts);
    static QString pointsToQString(const std::vector<Eigen::Vector3d> &pts, const char *sep="\n");

//----opencv---
#ifndef ME_NO_CV
    /// cv::Point3d
    static QString point3dToQStr(cv::Point3d &pt);
    static QString point3fToQStr(cv::Point3f &pt);
    static void point3dFromQStr(QString &str, cv::Point3d &pt);

    static QString pointsToQString(const std::vector<cv::Point3d> &pts);
    static QString pointsToQString(const std::vector<cv::Point3f> &pts);
    static QString pointsToQString(const std::vector<cv::Point2f> &pts);
    static void pointsFromQString(QString &strPts, std::vector<cv::Point3d> &pts);
#endif
};


#endif // MESTRUTIL_H
